package com.zsgeek.wisdchain.qutu.tools;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 使用md5的算法进行加密的Utils
 */
public class Md5Utils {

    public static String getmMd5(String plainText) {
        byte[] secretBytes;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException("没有md5这个算法！");
        }
        StringBuilder md5code = new StringBuilder(new BigInteger(1, secretBytes).toString(16));
        int md5Start = 32;
        for (int i = 0; i < md5Start - md5code.length(); i++) {
            md5code.insert(0, "0");
        }
        return md5code.toString();
    }

    public static String a(String var0) {
        try {
            MessageDigest var1 = MessageDigest.getInstance("MD5");
            var1.update(var0.getBytes());
            return b(var1.digest());
        } catch (NoSuchAlgorithmException var2) {
            var2.printStackTrace();
            return "";
        }
    }

    public static String a(byte[] var0) {
        try {
            MessageDigest var1 = MessageDigest.getInstance("MD5");
            var1.update(var0);
            return b(var1.digest());
        } catch (NoSuchAlgorithmException var2) {
            var2.printStackTrace();
            return "";
        }
    }

    private static String b(byte[] var0) {
        StringBuilder var1 = new StringBuilder(var0.length * 2);

        for (byte aVar0 : var0) {
            var1.append(Character.forDigit((aVar0 & 240) >> 4, 16));
            var1.append(Character.forDigit(aVar0 & 15, 16));
        }

        return var1.toString();
    }

}


